#ifndef UTILS_H
#define UTILS_H

#include <cstdint>

inline uint32_t clp2(uint32_t x)
{
       --x;
        x = x | (x >> 1);
        x = x | (x >> 2);
        x = x | (x >> 4);
        x = x | (x >> 8);
        x = x | (x >> 16);
        return ++x;
}

inline uint32_t log2(uint32_t x)
{
    uint32_t n = 0;
    while (x > 0)
    {
        x = x >> 1;
        if (x > 0)
        ++n;
    }

    return n;
}

#endif